﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace Runda.EShop.Common.Utility
{
    public static class ControlExtension
    {
        public static void BindEnum(this DropDownList ddl, EnumDescAttribute[] enums)
        {
            ddl.DataSource = enums;
            ddl.DataTextField = "enumDisplayText";
            ddl.DataValueField = "EnumValue";
            ddl.DataBind();

            //foreach (EnumDescAttribute eda in enums)
            //{
            //    ddl.Items.Add(new ListItem(eda.EnumDisplayText, eda.EnumValue.ToString()));
            //}
        }


        public static DateTime FormatToDate(this DateTime dt)
        {
            DateTime val = new DateTime(dt.Year, dt.Month, dt.Day);
            return val;
        }
 
        public static string ToEmptyWhenNull(this string Orginal)
        {
            if (string.IsNullOrEmpty(Orginal))
            {
                return string.Empty;
            }
            return Orginal;
        } 
    }
}
